;
(function () {
  new Vue({
    el: '#visitor-editor',
    data: {
      radioData: [
				{name: '线索', code: 'XS'},
				{name: '客户', code: 'KH'},
				{name: '不关联', code: 'NO'},
			],
			selectRadioData: [],			
			yxRadioData: [],
			selectYxRadioData: [],
			customerXsFlag: false,
			id: hlUrlUtil.GetQueryString('id'),
			fieldData: [],
			oneHang: ['text','radio','checkbox'],
			visitorTypeList: [],
			selectVisitorType: [],
			channelTypeData: [],
			selectChannelType:[],
			channelNameData: [],
			selectChannelName: [],
			industryData: [],
			selectIndustry: [],
			companyType: [{ name: '公司', code: 'QY' }, { name: '个人', code: 'PE' }],
			selectCompanyType: [],
			selectCompanyPopType: [],
			isClueShow: false,
			keyword: '',
			clueData: [],
			selectClue: [],
			originData: [],
			selectOrigin: [],
			querySelectOrigin: [],
			isCustomer: false,
			customerData: [],
			selectCustomerData: [],
			querySelectCustomerData: [],
			intentAreaData: [],
			selectIntentArea: [],
			
			consult_time: '',
			customer_name: '',
			customer_lperson: '',
			customer_phone: '',
			intermediary_name: '',
			intermediary_phone: '',
			intent_begin_time: '',
			intent_end_time: '',
			intent_acreage_count: '',
			intent_parking_count: '',
			intent_project_name: '',
			
			//意向开始
			yxShow: false,
			intentionTypes: [
				{ name: '整租', code: 'ER'}, 
				{ name: '工位', code: 'WR'	},
			],
			selectIntentionType: ['ER'],
			yxProjectData: [],
			selectYxProject: [],
			buildingData: [],
			selectBuild: [],
			floorData: [],
			selectFloor: [],
			unitData: [],
			selectUnit: [],
			positionData: [],
			buildingName: '',
			floorName: '',
			unitName: '',			
			submitUnitPositions: [],
			querySubmitUnitPositions: [],
			queryPositionHandle: [],
			isIntentionShow: false,
			
			tmpData: [],
			resData: []
    },    
    created() {
			//意向项目
			this.yxProject()
			this.visitorTypeData()
			this.getChannelTypeData()
			this.getIndustry()
			this.getClue()
			this.getSourceData()
			this.getCustomerLevel()
			this.customerGet()
			this.intentAreaDataGet()
			if (!this.id) {
				this.marketCustomizeDt([])
			}
			if (this.id) {
				this.getDetail()
			}
    },
		watch: {
			selectYxProject (val) {				
				for (let i = 0; i < this.yxProjectData.length; i++) {
					if (val.indexOf(this.yxProjectData[i].projectId) > -1) {
						this.intent_project_name = JSON.parse(JSON.stringify(this.yxProjectData[i].projectName))
						break
					}
				}
			}
		},
    methods: {
			//关联对象切换
      radioHandleClick () {
				this.querySelectOrigin = []
				this.querySelectCustomerData = []
				this.customerXsFlag = false
			},
			//获取详情
			getDetail() {
				hlhttp.get({
					url: 'visitor_form_info',
					data: {
						id: this.id
					},
					success: (data) => {		
						
						this.tmpData = data.pageCustomizeComponentBizContentList ? data.pageCustomizeComponentBizContentList : []
						
						this.selectRadioData = data.refCstmrType ? [data.refCstmrType] : []
						
						if (data.refCstmrType == 'XS') {
							data.visitorFormRefCstmrList.map(item => {
								item.sourceValue = item.sourceVal
								item.id = data.refCstmrId
							})
							this.querySelectOrigin = data.visitorFormRefCstmrList
						}
						
						if (data.refCstmrType == 'KH') {	
							data.visitorFormRefCstmrList.map(item => {
								item.id = data.refCstmrId
								item.shortName = item.customerShortName
							})
							this.querySelectCustomerData = data.visitorFormRefCstmrList
						}
						
						this.consult_time = hlDateUtil.formatUTCDate(data.consultTime, 'yyyy-MM-dd')
						this.selectVisitorType = data.type ? [data.type] : []
						this.selectChannelType = data.channelCategoryCode ? [data.channelCategoryCode] : [],
						//渠道名称
						this.getChannelNameData()
						this.selectChannelName = data.channelNameCode ? [data.channelNameCode] : []
						this.intermediary_name = data.intermediaryName
						this.intermediary_phone = data.intermediaryPhone
						this.customer_name = data.customerName
						this.selectCompanyType = data.customerType ? [data.customerType] : []
						this.selectIndustry = data.industryCode ? [data.industryCode] : []
						this.customer_lperson = data.customerLperson
						this.customer_phone = data.customerPhone
						this.selectYxRadioData = data.intentLevel ? [data.intentLevel] : []
						this.intent_begin_time = hlDateUtil.formatUTCDate(data.intentBeginTime, 'yyyy-MM-dd')
						this.intent_end_time = hlDateUtil.formatUTCDate(data.intentEndTime, 'yyyy-MM-dd')
						this.selectIntentionType = data.intentContractType ? [data.intentContractType] : []						
						if (data.intentContractType == 'ER') {
							this.selectIntentArea = data.intentAcreageCode ? [data.intentAcreageCode] : []
						}
						if (data.intentContractType == 'WR') {
							this.intent_acreage_count = data.intentAcreageCode
						}
						this.intent_parking_count = data.intentParkingCount;
						this.customerXsFlag = data.intentSynchronizationFlag == 'Y' ? true : false
						this.selectYxProject = data.intentProjectId ? [data.intentProjectId] : []
						if (data.intentProjectId) {
							this.yxShow = true
						}
						if (data.projectInfo) {							
							if (data.projectInfo.units && data.projectInfo.units.length) {
								data.projectInfo.units.map(item => {
									this.querySubmitUnitPositions.push({
										"building_id": item.buildingId, 
										"building_name": item.buildingName,  
										"floor_id": item.floorId,  
										"floor_num": item.floorNum, 
										"unit_id": item.unitId, 
										"unit_name": item.unitName,
										"unit_acreage": item.unitAcreage + '',
										"code": item.unitId
									})
								})
							}
							if (data.projectInfo.wps && data.projectInfo.wps.length) {
								data.projectInfo.wps.map(item => {
									this.submitUnitPositions.push({
										"building_id": item.buildingId,
										"building_name": item.buildingName, 
										"floor_id": item.floorId,  
										"floor_num": item.floorNum, 
										"unit_id": item.unitId, 
										"unit_name": item.unitName,
										"wp_acreage": '0',
										"wp_id": item.wpId,
										 "wp_name": item.wpName,
										"code": item.wpId
									})
								})	
								this.querySubmitUnitPositions = JSON.parse(JSON.stringify(this.submitUnitPositions))
								let newData = hlArrayUtil.removeRepeat(this.submitUnitPositions, 'unit_id')					
								newData.map(item => {item.child = []})
								this.submitUnitPositions.map(item1 => {
									newData.map(item2 => {
										if (item1.unit_id == item2.unit_id) {
											item2.child.push({name: item1.wp_name, id: item1.code})
										}
									})
								})
								this.queryPositionHandle = JSON.parse(JSON.stringify(newData))
							}
						}						
						//自定义信息
						this.marketCustomizeDt(data.customConfigProperty ? JSON.parse(data.customConfigProperty) : [])
					}
				})
			},
			
			//同步至 线索/客户 初步意向
			sycCustomerXS () {
				this.customerXsFlag = !this.customerXsFlag
			},
			//需求面积
			intentAreaDataGet () {
				var that = this
				hlhttp.get({
					url: 'configure/dict',
					data: {
						module_code: 'ZHSH',
						config_name: 'ZS_INTENT_AREA'
					},
					success: (data) => {
						data.map(item => {
							item.name = item.dictName
							item.code = item.dictCode
							if (item.status == 'Y') {
								this.intentAreaData.push(item)
							}
						})	
					},
				})
			},
			//自定义字段获取
			marketCustomizeDt (val) {
				return
			  var that = this
				hlhttp.get({
					url: 'configure/customize_column',
					data: {
					  module: 'ZHSH',
					  config_name: 'ZS_VISITOR_LIST_CUSTOMIZE_COLUMNS',
					},
					success: (res) => {
			      let arr = [...res.customizeColumns, ...res.systemColumns]
			      for (var i = arr.length - 1; i >= 0; i--) {
			        if (arr[i].isValid == 'false') {
			          arr.splice(i,1)
			        }
						}
						//去除多余数据（未启动，无关联）
						// if(val){
			      //   arr = hlArrayUtil.removeRepeat([...val,...arr], 'configCode');
			      // }
			      
			       //若有合同详情，则合并,去重（保留合同）
			      let textList = []
			      let noTextList = []
			      arr.map((item,index) =>{
			        if(item.fieldType == 'text'){
			          textList.push(item)
			        }else{
			          noTextList.push(item)
			        }
			      })
			      arr = [...noTextList,...textList]
			      //重新排序，将文本类型放到最后
			      
			      arr.map(item => {
			        if(!item.select){
			          if (item.fieldType == 'radio' || item.fieldType == 'checkbox' || item.fieldType == 'select') {
			            item.select = [];
			            item.selectArr = item.fieldRange.split(',')
			            item.selectArrCopy = []
			            item.selectArr.map(item0 => {
			              item.selectArrCopy.push({
			                name: item0,
			                code: item0
			              })
			            })
			  
			          } else {
			            item.select = '';
			          }
			        }
			      })
			      if(val){
			        val.map(item =>{
			          arr.map(single =>{
			            if(single.configCode == item.configCode){
			              single.select = item.select
			            }
			          })
			        })
			      }
						that.fieldData = arr
					}
				})
			},
			// 检测自定义字段填写是否符合要求
			checkCustom() {
			  let flag = true
			  this.resData.map(item => {
			  	if (item.requiredFlag == 'Y' && (!item.value || !item.value.length) && item.type != 'line') {
			  	  flag = false
			  	}
			  })	
			  return flag
			},
			//访客单类型接口
			visitorTypeData () {
				this.visitorTypeList = []
				hlhttp.get({
					url: 'configure/dict',
					data: {
						module_code: 'ZHSH',
						config_name: 'ZS_VISITOR_LIST_TYPE'
					},
					success: (data) => {
						data.map(item => {
							item.code = item.dictCode
							item.name = item.dictName
							if (item.status == 'Y') {
								this.visitorTypeList.push(item)
							}
						})						
					},
				})
			},
			//渠道分类
			getChannelTypeData () {	
				this.channelTypeData = []
			  hlhttp.get({
			    url: 'configure/dict',
			    data: {module_code: 'ZHSH', config_name: 'ZS_CHANNEL_CATE'},
			    success: data => {
						data.map(item => {
							item.code = item.dictCode
							item.name = item.dictName
							if (item.status == 'Y') {
								this.channelTypeData.push(item)
							}
						})
			    }
			  })
			},
			//渠道名称
			getChannelNameData () {
				this.channelNameData = []
				this.selectChannelName = []
			  hlhttp.get({
			    url: 'configure/dict',
			    data: {module_code: 'ZHSH', config_name: 'ZS_CHANNEL_NAME', parent_dict_code: this.selectChannelType[0]},
			    success: data => {
						data.map(item => {
							item.code = item.dictCode
							item.name = item.dictName
							if (item.status == 'Y') {
								this.channelNameData.push(item)
							}
						})
			    }
			  })
			},
			//所属行业
			getIndustry () {	
				this.industryData = []
				hlhttp.get({
					url: 'configure/dict',
					data: {module_code: 'ZHSH',config_name: 'ZS_INDUSTRY_TYPE'},
					success: (data) => {
						data.map(item => {
							item.code = item.dictCode
							item.name = item.dictName
							if (item.status == 'Y') {
								this.industryData.push(item)
							}
						})
					}
				})
			},
			//客户意向水平
			getCustomerLevel () {	
				this.industryData = []
				hlhttp.get({
					url: 'configure/dict',
					data: {module_code: 'ZHSH',config_name: 'ZS_CUSTOMER_INTEND_LEVEL'},
					success: (data) => {
						data.map(item => {
							item.code = item.dictCode
							item.name = item.dictName
							if (item.status == 'Y') {
								this.yxRadioData.push(item)
							}
						})
					}
				})
			},
			//线索来源
			getClue () {
				this.clueData = []
				hlhttp.get({
					url: 'configure/dict',
					data: {module_code: 'ZHSH0SHJI',config_name: 'SJ_SOURCE'},
					success: (data) => {
						data.map(item => {
							item.code = item.dictCode
							item.name = item.dictName
							if (item.status == 'Y') {
								this.clueData.push(item)
							}
						})
					}
				})
			},
			getSourceData () {
				const self = this
				var data = {
					"origin": self.selectClue.length ? self.selectClue[0] : '#',
					"assignee_id": '#',
					"channel_category_code": '#',
					"channel_name_code": '#',
					"status": '#',
					'industry': '#',
					"keyword": self.keyword || '#',
					"limit": 100000,
					"page": 1,
					"columns": '#',
					"orders": '#'
				}

				hlhttp.get({
					url: 'customer/biz_oppt_search',
					data: data,
					success: res => {
						res.businessOpportunitys.map(item => {
							item.code = item.id
						})
						this.originData = res.businessOpportunitys
					}
				})
			},
			//线索重置
			resetSource () {
				this.selectClue = []
				this.keyword = ''
				this.getSourceData()
			},
			// 显示意向
			showClue () {
				if (this.selectRadioData.indexOf('XS') > -1) {
					this.isClueShow = true;
					this.selectOrigin = JSON.parse(JSON.stringify(this.querySelectOrigin))
				}
				if (this.selectRadioData.indexOf('KH') > -1) {
					this.isCustomer = true;
					
				}
			},
			//选择某个线索
			selectClueId (item) {
				this.selectOrigin = [item]
			},
			//关闭线索
			closeSource () {
				this.isClueShow = false;
				this.selectOrigin = []
			},
			//确认选中线索
			querySelectOriginBtn () {
				this.querySelectOrigin = JSON.parse(JSON.stringify(this.selectOrigin))
				this.closeSource()
			},
			customerGet () {
				var self = this;
				var submitData = {
					'keyword': self.keyword || '#',
					'customer_type': self.selectCompanyPopType.length ? self.selectCompanyPopType[0] : '#',
					'industry_code': '#',
					'rperson_id':'#',
					'channel_category_code': '#',
					'channel_name_code': '#',
					'customer_state': '#',
					'black_status': '#',
					'limit': 1000000,
					'page': 1,
					'columns': '#',
					'orders': '#',
				}

				hlhttp.get({
					url: 'customer_manager_search',
					data: submitData,
					success: function (data) {					
						self.customerData = data.myCustomers;
					}
				})
			},
			//客户重置
			resetSource () {
				this.selectCompanyPopType = []
				this.keyword = ''
				this.customerGet()
			},
			//选择某个客户
			selectCustomerId (item) {
				this.selectCustomerData = [item]
			},
			//关闭客户
			closeCustomer () {
				this.isCustomer = false;
				this.selectCustomerData = []
			},
			//确认选中客户
			querySelectCustomerBtn () {
				this.querySelectCustomerData = JSON.parse(JSON.stringify(this.selectCustomerData))
				this.closeCustomer()
			},
			//客户详情
			customerDetail () {
				hlhttp.get({
					url: 'customer,cincb_info',
					data: {customer_id: this.querySelectCustomerData[0].id},
					success: (data) => {
						this.selectChannelType = data.channelCategoryCode ? [data.channelCategoryCode] : []
						this.selectChannelName = data.channelNameCode ? [data.channelNameCode] : []
						this.customer_name = data.name
						this.selectCompanyType = data.type ? [data.type] : []
						this.selectIndustry = data.industry ? [data.industry] : []
						this.customer_lperson = data.lperson
						this.customer_phone = data.phone
						if (data.channelCategoryCode) {
							this.getChannelNameData()
						}
					}
				})
			},
			//线索详情
			clueDetail () {
				hlhttp.get({
					url: 'customer/biz_oppt_info',
					data: {sj_id: this.querySelectOrigin[0].id},
					success: (data) => {
						this.selectChannelType = data.themeInfo.channelCategoryCode ? [data.themeInfo.channelCategoryCode] : []
						this.selectChannelName = data.themeInfo.channelNameCode ? [data.themeInfo.channelNameCode] : []
						this.customer_name = data.zlfInfo.customerName
						this.selectCompanyType = data.zlfInfo.customerType ? [data.zlfInfo.customerType] : []
						this.selectIndustry = data.zlfInfo.industryCode ? [data.zlfInfo.industryCode] : []
						this.customer_lperson = data.zlfInfo.lperson
						this.customer_phone = data.zlfInfo.phone
						if (data.themeInfo.channelCategoryCode) {
							this.getChannelNameData()
						}
					}
				})
			},
			//点击同步部分客户信息
			clickSycCustomer () {
				if (this.selectRadioData.indexOf('KH') > -1) {
					this.customerDetail()
				}
				if (this.selectRadioData.indexOf('XS') > -1) {
					this.clueDetail()
				}
			},
			
			//必填验证
			checkValidate () {
				if (!this.selectRadioData.length) {
					hl.toast('请选择关联对象')
					return false
				}
				if (!this.consult_time) {
					hl.toast('请选择咨询日期')
					return false
				}
				if (!this.selectVisitorType.length) {
					hl.toast('请选择访客单类型')
					return false
				}
				if (!this.selectChannelType.length) {
					hl.toast('请选择渠道分类')
					return false
				}
				if (!this.customer_name) {
					hl.toast('请填写客户名称')
					return false
				}
				if (!this.selectCompanyType.length) {
					hl.toast('请选择客户类型')
					return false
				}
				if (!this.customer_lperson) {
					hl.toast('请填写联系人')
					return false
				}
				if (!this.customer_phone) {
					hl.toast('请填写联系方式')
					return false
				}
				if (!this.selectYxRadioData.length) {
					hl.toast('请选择意向水平')
					return false
				}
				if (this.yxShow) {
					if (!this.intent_begin_time || !this.intent_end_time) {
						hl.toast('请选择需求时间')
						return false
					}
					if (this.selectIntentionType.indexOf('ER') > -1) {
						if (!this.selectIntentArea.length) {
							hl.toast('请选择需求面积')
							return false
						}
					}
					if (this.selectIntentionType.indexOf('WR') > -1) {
						if (!this.intent_acreage_count) {
							hl.toast('请选择需求个数')
							return false
						}
					}
					if (!this.selectYxProject.length) {
						hl.toast('请选择意向项目')
						return false
					}
					if (!this.querySubmitUnitPositions.length || !this.querySubmitUnitPositions.length) {
						hl.toast('请选择意向单元')
						return false
					}					
				}
				return true
			},
			
			resMake (type, val) {
				// text  textarea mobile email phone  time date  dateTime
				let t0 = ['text', 'email', 'area', 'mobile', 'phone', 'time', 'date', 'dateTime', 'select', 'radio', 'checkbox'];						
				let t1 = ['file'];
				if (t0.indexOf(type) > -1) return val;
				if (t1.indexOf(type) > -1) {
					let data = []
					if (val) {
						val.map(item => {
							data.push(item.response ? item.response : item)
						})
					}
					return data
				}
			},
			
			newFieldsData () {
				let data = [];
				this.resData.map(item => {
					data.push({
						component_code: item.code,
						component_type: item.type,
						property: this.resMake(item.type, item.value)
					})
				})
				return data;
			},
			
			//新建
			params () {
				let ref_cstmr_id;
				if (this.selectRadioData.indexOf('XS') > -1 && this.querySelectOrigin.length) {
					ref_cstmr_id = this.querySelectOrigin[0].id
				}
				if (this.selectRadioData.indexOf('KH') > -1 && this.querySelectCustomerData.length) {
					ref_cstmr_id = this.querySelectCustomerData[0].id
				}
				let project_info = {
					project_id: this.selectYxProject[0],
					project_name: this.intent_project_name,
					stops: '#',
					wps: this.queryPositionHandle.length ? JSON.stringify(this.querySubmitUnitPositions) : '#',
					units: this.selectIntentionType.indexOf('ER') > -1 ? JSON.stringify(this.querySubmitUnitPositions) : '#'
				}
				let area = this.selectIntentArea.length ? this.selectIntentArea[0] : '#'
				if (!this.querySubmitUnitPositions.length && !this.queryPositionHandle.length) {
					this.customerXsFlag = false
				}
				let data = {
					type: this.selectVisitorType[0],
					consult_time: this.consult_time || '#',
					ref_cstmr_id: ref_cstmr_id || '#',
					ref_cstmr_type: this.selectRadioData[0],
					intermediary_name: this.intermediary_name || '#',
					intermediary_phone: this.intermediary_phone || '#',
					customer_name: this.customer_name || '#',
					customer_type: this.selectCompanyType[0],
					industry_code: this.selectIndustry.length ? this.selectIndustry[0] : '#',
					customer_lperson: this.customer_lperson || '#',
					customer_phone: this.customer_phone || '#',
					channel_category_code: this.selectChannelType.length ? this.selectChannelType[0] : '#',
					channel_name_code: this.selectChannelName.length ? this.selectChannelName[0] : '#',
					intent_level: this.selectYxRadioData[0],
					intent_begin_time: this.intent_begin_time || '#',
					intent_end_time: this.intent_end_time || '#',
					intent_contract_type: this.selectIntentionType[0],
					intent_acreage_code: this.selectIntentionType.indexOf('ER') > -1 ? area : (this.intent_acreage_count || '#'),
					intent_parking_count: this.intent_parking_count || '#',
					intent_project_id: this.yxShow ? this.selectYxProject[0] : '#',
					intent_project_name: this.yxShow ? this.intent_project_name : '#',
					intent_synchronization_flag: this.customerXsFlag ? 'Y' : 'N',
					custom_config_property: JSON.stringify(this.fieldData),
					page_customize_component_biz_content: JSON.stringify(this.newFieldsData()),
					project_info: this.yxShow ? JSON.stringify(project_info) : '#'
				}				
				return data;
			},
			createPost () {				
				hlhttp.post({
					url: 'visitor_form_info',
					data: this.params(),
					success: () => {
						hlUrlUtil.goTo('visitorList', { ddtab: true, clear: true }, false)
					}
				})
			},
			editPut () {
				let data = JSON.parse(JSON.stringify(this.params()))
				data.id = this.id
				hlhttp.put({
					url: 'visitor_form_info',
					data: data,
					success: () => {
						hlUrlUtil.goTo('visitorList', { ddtab: true, clear: true }, false)
					}
				})
			},
			saveSubmit () {
				if (!this.checkValidate()) return;
				if(!this.checkCustom()){
				  hl.toast('请完成自定义字段')
				  return
				}
				if (!this.id) this.createPost();
				if (this.id) this.editPut();
			},
			
			//意向开始
			//显示意向信息
			yxShowDisplay () {
				this.yxShow = true
			},
			//意向项目
			yxProject () {
				hlhttp.get({
					url: 'user/projects',
					success: (data) => {
						data.map(item => {
							item.name = item.projectName;
							item.code = item.projectId;
						})
						this.yxProjectData = data;
					}
				})
			},
			//楼宇接口
			yxBuilding () {
				hlhttp.get({
					url: 'project/buildings',
					data: {project_id: this.selectYxProject[0]},
					success: (data) => {
						data.map(item => {
							item.code = item.buildingId;
						})
						this.buildingData = data;
					}
				})
			},
			//楼层接口
			yxFloor (ops) {
				console.log(ops)
				this.buildingName = ops ? ops[0].name : this.buildingName
				this.floorData = []
				this.unitData = []
				this.selectFloor = []
				this.floorName = ''
				hlhttp.get({
					url: 'building/floors',
					data: {project_id: this.selectYxProject[0], building_id: this.selectBuild[0]},
					success: (data) => {
						data.map(item => {
							item.code = item.floorId;
							item.name = item.floorName;
						})
						this.floorData = data;
					}
				})
			},
			//单元接口
			yxUnit (ops) {
				console.log(ops)
				this.floorName = ops ? ops[0].name : this.floorName
				this.unitData = []
				hlhttp.get({
					url: 'floor/units',
					data: {project_id: this.selectYxProject[0], building_id: this.selectBuild[0], floor_id: this.selectFloor[0]},
					success: (data) => {
						data.map(item => {
							item.code = item.unitId;
							item.name = item.unitName;
							if (item.unitType == 'BU' && item.rentState != 'ZY') {
								this.unitData.push(item)
							}
						})
					}
				})
			},
			yxUnit1 (ops) {
				console.log(ops)
				this.floorName = ops ? ops[0].name : this.floorName
				this.unitData = []
				hlhttp.get({
					url: 'floor/units',
					data: {project_id: this.selectYxProject[0], building_id: this.selectBuild[0], floor_id: this.selectFloor[0]},
					success: (data) => {
						data.map(item => {
							item.code = item.unitId;
							item.name = item.unitName;
							if (item.unitType == 'WP') {
								this.unitData.push(item)
							}
						})
					}
				})
			},
			//工位接口
			yxPosition (ops) {
				this.unitName = this.unitName = ops ? ops[0].name : this.unitName
				this.positionData = []
				hlhttp.get({
					url: 'units/positions',
					data: {unit_id: this.selectUnit[0]},
					success: (data) => {
						data.map(item => {
							item.code = item.positionId;
							item.name = item.positionName;
						})
						this.positionData = data;
					}
				})
			},
			//项目切换
			changeProject (ops) {				
				this.intent_project_name = ops ? ops[0].name : ''
				this.buildingData = []
				this.floorData = []
				this.unitData = []
				this.selectFloor = []
				this.floorName = ''
				this.buildingName = ''
				this.submitUnitPositions = []
				this.querySubmitUnitPositions = []
				this.queryPositionHandle = []
			},
			delYx () {
				this.changeProject()
				this.intent_begin_time = ''
				this.intent_end_time = ''
				this.intent_parking_count = ''
				this.selectIntentionType = ['ER']
				this.intent_acreage_count = ''
				this.selectYxProject = []
				this.selectIntentArea = []
				this.yxShow = false
				this.customerXsFlag = false
			},
			//是否选中
			selectUnitPosition (arr, code, type) {
				let sIndex = -1;
				let model = type ? type : 'code'
				arr.map((item, index) => {
					if (item[model] == code) {
						sIndex = index
					}
				})
				return sIndex
			},
			//选中单元
			selectUnitData (item) {
				if (this.selectUnitPosition(this.submitUnitPositions, item.code) == -1) {					
					this.submitUnitPositions.push({
						"building_id": item.buildingId, 
						"building_name": this.buildingName,  
						"floor_id": item.floorId,  
						"floor_num": item.floor + '', 
						"unit_id": item.code, 
						"unit_name": item.unitName,
						"unit_acreage": item.acreage + '', 
						"code": item.code
					})					
				} else {
					this.submitUnitPositions.splice(this.selectUnitPosition(this.submitUnitPositions, item.code), 1)
				}
			},
			//选中工位
			selectPositionData (item) {
				if (this.selectUnitPosition(this.submitUnitPositions, item.code) == -1) {
					this.submitUnitPositions.push({
						"building_id": this.selectBuild[0], 
						"building_name": this.buildingName,  
						"floor_id": this.selectFloor[0], 
						"floor_num": this.floorName + '', 
						"unit_id": this.selectUnit[0], 
						"unit_name": this.unitName,
						"wp_acreage": '0',
						"wp_id": item.code,    
						 "wp_name": item.name,
						"code": item.code
					})					
				} else {
					this.submitUnitPositions.splice(this.selectUnitPosition(this.submitUnitPositions, item.code), 1)
				}
			},
			//工位删除特除处理
			positionDelHanld () {
				this.submitUnitPositions = []
				let newData = [];
				this.queryPositionHandle.map(item => {
					item.child.map(item1 => {
						this.submitUnitPositions.push({
							"building_id": item.building_id,
							"building_name": item.building_name, 
							"floor_id": item.floor_id, 
							"floor_num": item.floor_num, 
							"unit_id": item.unit_id, 
							"unit_name": item.unit_name, 
							"wp_acreage": '0',
							"wp_id": item.wp_id,  
							 "wp_name": item1.name,
							"code": item1.id
						})	
					})
				})				
				this.querySubmitUnitPositions = JSON.parse(JSON.stringify(this.submitUnitPositions))
			},
			// 点击初步意向
			clickYxButton () {				
				if (!this.selectYxProject.length) {
					hl.toast('请选择意向项目')
					return
				}
				this.isIntentionShow = true;
				if (this.selectIntentionType.indexOf('ER') > -1) {
					this.submitUnitPositions = JSON.parse(JSON.stringify(this.querySubmitUnitPositions))
				}
				if (this.selectIntentionType.indexOf('WR') > -1) {					
					this.positionDelHanld()
				}
				this.yxBuilding()
			},
			//关闭意向框
			closeYxDialog () {
				this.selectBuild = []
				this.selectFloor = []
				this.buildingData = []
				this.floorData = []
				this.floorName = ''
				this.positionData = []
				this.unitData = []
				this.selectUnit = []
				this.unitName = ''
				this.isIntentionShow = false
			},
			//删除单元
			delUnit (i) {
				this.querySubmitUnitPositions.splice(i, 1)
			},
			//删除工位
			delPosition (i1, i2) {
				this.queryPositionHandle[i1].child.splice(i2, 1)
				if (!this.queryPositionHandle[i1].child.length) {
					this.queryPositionHandle.splice(i1, 1)
				}
				this.positionDelHanld()
			},
			//切换需求类型
			handleClickType () {
				this.querySubmitUnitPositions = []
				this.submitUnitPositions = []
				this.queryPositionHandle = []
			},
			//确认添加
			querySubmitUnitPositionsEv () {
				if (this.selectIntentionType.indexOf('ER') > -1) {
					this.querySubmitUnitPositions = JSON.parse(JSON.stringify(this.submitUnitPositions))
				}
				if (this.selectIntentionType.indexOf('WR') > -1) {					
					this.querySubmitUnitPositions = JSON.parse(JSON.stringify(this.submitUnitPositions))
					let newData = hlArrayUtil.removeRepeat(this.submitUnitPositions, 'unit_id')					
					newData.map(item => {item.child = []})
					this.submitUnitPositions.map(item1 => {
						newData.map(item2 => {
							if (item1.unit_id == item2.unit_id) {
								item2.child.push({name: item1.wp_name, id: item1.code})
							}
						})
					})
					this.queryPositionHandle = JSON.parse(JSON.stringify(newData))
				}
				this.closeYxDialog()
			}
    },
    mounted: function () {     
      
    },
		filters: {
		  formatDate: function (time) {
		    if (time === undefined) return '--'
		    return hlDateUtil.formatUTCDate(time, 'yyyy-MM-dd')
		  },
		  formatDatehms: function (time) {
		    if (time === undefined) return '--'
		    return hlDateUtil.formatUTCDate(time, 'yyyy-MM-dd HH:mm:ss')
		  },
		  formatUndefined: function (item) {
		    if (!item) return '--'
		    return item
		  },
		  formatNum: function (item) {
		    if (item === undefined) return '--'
		    return hlNumberUtil.formatNum(item)
		  }
		},
  })

}())
